package cn.iocoder.yudao.framework.common.enums.trade;

import cn.hutool.core.util.ArrayUtil;
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 贵金属交易 - 业务类型枚举
 *
 * @author 芋道源码
 */
@Getter
@AllArgsConstructor
public enum TransactionTypeEnum implements ArrayValuable<Integer> {

    FULL_PAY_BUY(1, "全款买料"),
    FULL_PAY_SELL(2, "全款卖料"),
    PRICE_LOCK_BUY(3, "锁价买料"),
    PRICE_LOCK_SELL(4, "锁价卖料"), 
    STORE_METAL(5, "存料"),
    TAKE_METAL(6, "提料"),
    EXCHANGE_METAL(7, "旧料兑换"),
    ;

    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(TransactionTypeEnum::getType).toArray();

    /**
     * 类型
     */
    private final Integer type;
    /**
     * 描述
     */
    private final String desc;

    public static TransactionTypeEnum getEnum(Integer orderType) {
        if (orderType == null) {
            return null;
        }
        return ArrayUtil.firstMatch(item -> item.getType().equals(orderType), values());
    }

    public static boolean isSale(Integer orderType) {
        return ObjectUtils.equalsAny(orderType,
                FULL_PAY_BUY.getType(), PRICE_LOCK_BUY.getType(), EXCHANGE_METAL.getType());
    }

    @Override
    public Integer[] array() {
        return new Integer[0];
    }

    public static boolean isLockPrice(Integer type) {
        return PRICE_LOCK_BUY.getType().equals(type) || PRICE_LOCK_SELL.getType().equals(type);
    }
} 